/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.utils.format;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.xml.sax.SAXException;
import comandaXM.excepcions.ExceptionXML;  


/**
 *
 * @author xmarti
 */
public class Format {
    public void write(String path, FormatJSplitPane jSplitPane ) throws ExceptionXML {
        FormatJSplitPaneXML_DOM dom = new FormatJSplitPaneXML_DOM();
        FormatJSplitPane js=null;
        File folder = new File("format");
        if(!folder.isDirectory())folder.mkdir();        
        try {
            dom.FormatJSplitPaneToXML(jSplitPane, "format/"+path);
        } catch (TransformerException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_WRITE_TRANSFORMER);
        } catch (IOException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_WRITE);
        } catch (ParserConfigurationException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_WRITE_PARSE);
        }
    }
    public FormatJSplitPane read(String path) throws ExceptionXML {
        FormatJSplitPane formatRead=null;
        FormatJSplitPaneXML_DOM dom = new FormatJSplitPaneXML_DOM();
        try {
            formatRead = dom.XMLtoFormatJSplitPane("format/"+path);
        } catch (ParserConfigurationException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_READ_TRANSFORMER);
        } catch (IOException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_READ_TRANSFORMER);
        } catch (SAXException ex) {
            throw new ExceptionXML(ExceptionXML.ERR_READ_TRANSFORMER);
        }
        return formatRead;
    }
}
